<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for src/serviceWorker.js</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../prettify.css" />
    <link rel="stylesheet" href="../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../index.html">All files</a> / <a href="index.html">src</a> serviceWorker.js
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>0/38</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>0/32</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>0/15</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>0/38</span>
      </div>
    </div>
  </div>
  <div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">// This optional code is used to register a service worker.
// register() is not called by default.
&nbsp;
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on subsequent visits to a page, after all the
// existing tabs open on the page have been closed, since previously cached
// resources are updated in the background.
&nbsp;
// To learn more about the benefits of this model and instructions on how to
// opt-in, read http://bit.ly/CRA-PWA
&nbsp;
const isLocalhost = <span class="cstat-no" title="statement not covered" >Boolean(</span>
  window.location.hostname === 'localhost' ||
    // [::1] is the IPv6 localhost address.
    window.location.hostname === '[::1]' ||
    // 127.0.0.1/8 is considered localhost for IPv4.
    window.location.hostname.match(
      /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
    )
);
&nbsp;
export function <span class="fstat-no" title="function not covered" >register(config) {</span>
<span class="cstat-no" title="statement not covered" >  if (process.env.NODE_ENV === 'production' &amp;&amp; 'serviceWorker' in navigator) {</span>
    // The URL constructor is available in all browsers that support SW.
    const publicUrl = <span class="cstat-no" title="statement not covered" >new URL(process.env.PUBLIC_URL, window.location.href);</span>
<span class="cstat-no" title="statement not covered" >    if (publicUrl.origin !== window.location.origin) {</span>
      // Our service worker won't work if PUBLIC_URL is on a different origin
      // from what our page is served on. This might happen if a CDN is used to
      // serve assets; see https://github.com/facebook/create-react-app/issues/2374
<span class="cstat-no" title="statement not covered" >      return;</span>
    }
&nbsp;
<span class="cstat-no" title="statement not covered" >    window.addEventListener('load', <span class="fstat-no" title="function not covered" >() =&gt; </span>{</span>
      const swUrl = `<span class="cstat-no" title="statement not covered" >${process.env.PUBLIC_URL}/service-worker.js`;</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >      if (isLocalhost) {</span>
        // This is running on localhost. Let's check if a service worker still exists or not.
<span class="cstat-no" title="statement not covered" >        checkValidServiceWorker(swUrl, config);</span>
&nbsp;
        // Add some additional logging to localhost, pointing developers to the
        // service worker/PWA documentation.
<span class="cstat-no" title="statement not covered" >        navigator.serviceWorker.ready.then(<span class="fstat-no" title="function not covered" >() =&gt; </span>{</span>
<span class="cstat-no" title="statement not covered" >          console.log(</span>
            'This web app is being served cache-first by a service ' +
              'worker. To learn more, visit http://bit.ly/CRA-PWA'
          );
        });
      } else {
        // Is not localhost. Just register service worker
<span class="cstat-no" title="statement not covered" >        registerValidSW(swUrl, config);</span>
      }
    });
  }
}
&nbsp;
function <span class="fstat-no" title="function not covered" >registerValidSW(swUrl, config) {</span>
<span class="cstat-no" title="statement not covered" >  navigator.serviceWorker</span>
    .register(swUrl)
    .then(<span class="fstat-no" title="function not covered" >registration</span> =&gt; {
<span class="cstat-no" title="statement not covered" >      registration.onupdatefound = <span class="fstat-no" title="function not covered" >() =&gt; </span>{</span>
        const installingWorker = <span class="cstat-no" title="statement not covered" >registration.installing;</span>
<span class="cstat-no" title="statement not covered" >        if (installingWorker == null) {</span>
<span class="cstat-no" title="statement not covered" >          return;</span>
        }
<span class="cstat-no" title="statement not covered" >        installingWorker.onstatechange = <span class="fstat-no" title="function not covered" >() =&gt; </span>{</span>
<span class="cstat-no" title="statement not covered" >          if (installingWorker.state === 'installed') {</span>
<span class="cstat-no" title="statement not covered" >            if (navigator.serviceWorker.controller) {</span>
              // At this point, the updated precached content has been fetched,
              // but the previous service worker will still serve the older
              // content until all client tabs are closed.
<span class="cstat-no" title="statement not covered" >              console.log(</span>
                'New content is available and will be used when all ' +
                  'tabs for this page are closed. See http://bit.ly/CRA-PWA.'
              );
&nbsp;
              // Execute callback
<span class="cstat-no" title="statement not covered" >              if (config &amp;&amp; config.onUpdate) {</span>
<span class="cstat-no" title="statement not covered" >                config.onUpdate(registration);</span>
              }
            } else {
              // At this point, everything has been precached.
              // It's the perfect time to display a
              // "Content is cached for offline use." message.
<span class="cstat-no" title="statement not covered" >              console.log('Content is cached for offline use.');</span>
&nbsp;
              // Execute callback
<span class="cstat-no" title="statement not covered" >              if (config &amp;&amp; config.onSuccess) {</span>
<span class="cstat-no" title="statement not covered" >                config.onSuccess(registration);</span>
              }
            }
          }
        };
      };
    })
    .catch(<span class="fstat-no" title="function not covered" >error</span> =&gt; {
<span class="cstat-no" title="statement not covered" >      console.error('Error during service worker registration:', error);</span>
    });
}
&nbsp;
function <span class="fstat-no" title="function not covered" >checkValidServiceWorker(swUrl, config) {</span>
  // Check if the service worker can be found. If it can't reload the page.
<span class="cstat-no" title="statement not covered" >  fetch(swUrl)</span>
    .then(<span class="fstat-no" title="function not covered" >response</span> =&gt; {
      // Ensure service worker exists, and that we really are getting a JS file.
      const contentType = <span class="cstat-no" title="statement not covered" >response.headers.get('content-type');</span>
<span class="cstat-no" title="statement not covered" >      if (</span>
        response.status === 404 ||
        (contentType != null &amp;&amp; contentType.indexOf('javascript') === -1)
      ) {
        // No service worker found. Probably a different app. Reload the page.
<span class="cstat-no" title="statement not covered" >        navigator.serviceWorker.ready.then(<span class="fstat-no" title="function not covered" >registration</span> =&gt; {</span>
<span class="cstat-no" title="statement not covered" >          registration.unregister().then(<span class="fstat-no" title="function not covered" >() =&gt; </span>{</span>
<span class="cstat-no" title="statement not covered" >            window.location.reload();</span>
          });
        });
      } else {
        // Service worker found. Proceed as normal.
<span class="cstat-no" title="statement not covered" >        registerValidSW(swUrl, config);</span>
      }
    })
    .catch(<span class="fstat-no" title="function not covered" >() =&gt; </span>{
<span class="cstat-no" title="statement not covered" >      console.log(</span>
        'No internet connection found. App is running in offline mode.'
      );
    });
}
&nbsp;
export function <span class="fstat-no" title="function not covered" >unregister() {</span>
<span class="cstat-no" title="statement not covered" >  if ('serviceWorker' in navigator) {</span>
<span class="cstat-no" title="statement not covered" >    navigator.serviceWorker.ready.then(<span class="fstat-no" title="function not covered" >registration</span> =&gt; {</span>
<span class="cstat-no" title="statement not covered" >      registration.unregister();</span>
    });
  }
}
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Thu Feb 14 2019 13:30:41 GMT+0800 (GMT+08:00)
</div>
</div>
<script src="../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../sorter.js"></script>
</body>
</html>
